from django.db import models

# Create your models here.
class Student(models.Model):
    SEX_CHOICES = (
        (0,'女'),
        (1,'男')
    )
    name = models.CharField(max_length=20,verbose_name='姓名') #verbose显示备注为姓名(在admin后台中显示)
    age = models.IntegerField(verbose_name='年龄',null=True,blank=True)#blank是前端可以不给数据
    sex = models.IntegerField(verbose_name='性别',null=True,blank=True,choices=SEX_CHOICES)#加上choices会变成下拉框
    create_time = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True,verbose_name='更新时间')
    is_delete = models.BooleanField(default=False,verbose_name='逻辑删除')#逻辑删除，不会真正删除的，只是把界面上的信息删除，不让用户看到并操作而已，数据还在后台，

    # ForeignKey为一对多的外键，外面一个键对应里面多个键
    classes = models.ForeignKey('Classes',on_delete=models.CASCADE,verbose_name='班级')

    #逻辑删除
    def delete(self, using=None, keep_parents=False): #逻辑删除
        self.is_delete = True
        self.save()

class Classes(models.Model):
    name = models.CharField(max_length=30,verbose_name='班级名')
    slogan = models.TextField(null=True,blank=True,verbose_name='口号')#可以为空，前端也可以不传过来
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    # 逻辑删除
    def delete(self, using=None, keep_parents=False):  # 逻辑删除
        self.is_delete = True
        self.save()

    def __str__(self):
        return self.name


